class Solution(object):
    def canCross(self, stones):
        """
        :type stones: List[int]
        :rtype: bool
        """
        steps = {}
        for stone in stones:
            steps[stone] = set()
        steps[stones[0]].add(0)
        for stone in stones:
            for step in steps[stone]:
                next = step-1 
                if next>0 and stone+next in steps: steps[stone+next].add(step-1)
                next = step
                if next>0 and stone+next in steps: steps[stone+next].add(step)
                next = step+1
                if next>0 and stone+next in steps: steps[stone+next].add(step+1)
        return len(steps[stones[-1]])!=0

print(Solution().canCross([0,2]))